<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增人员资产')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-presion-add">
            <h4 class="form-header h4">人员资产信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员编号：</label>
                <div class="col-sm-8">
                    <input name="userId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资产编号：</label>
                <div class="col-sm-8">
                    <input name="assetsId" class="form-control" type="text">
                </div>
            </div>
            <h4 class="form-header h4">资产信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "assets/presion"
        var assetsTypeDatas = [[${@dict.getType('assets_type')}]];
        var assetsAreaDatas = [[${@dict.getType('area_type')}]];
        var assetsCompanyDatas = [[${@dict.getType('company')}]];
        var assetsStatusDatas = [[${@dict.getType('assets_status')}]];
        $("#form-presion-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-presion-add').serialize());
            }
        }

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'assetsName',
                    align: 'center',
                    title: '资产名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsType',
                    align: 'center',
                    title: '资产类别',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("assetsInfoList[%s].assetsType", index);
                        return $.common.dictToSelect(assetsTypeDatas, value, name);
                    }
                },
                {
                    field: 'assetsModel',
                    align: 'center',
                    title: '规格型号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsModel' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsSn',
                    align: 'center',
                    title: 'SN号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsSn' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsUnit',
                    align: 'center',
                    title: '计量单位',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsUnit' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsSource',
                    align: 'center',
                    title: '购入来源',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsSource' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsBuytime',
                    align: 'center',
                    title: '购入日期',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsBuytime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsPrice',
                    align: 'center',
                    title: '金额',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsPrice' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsArea',
                    align: 'center',
                    title: '所属区域',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("assetsInfoList[%s].assetsArea", index);
                        return $.common.dictToSelect(assetsAreaDatas, value, name);
                    }
                },
                {
                    field: 'assetsCompany',
                    align: 'center',
                    title: '所属公司',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("assetsInfoList[%s].assetsCompany", index);
                        return $.common.dictToSelect(assetsCompanyDatas, value, name);
                    }
                },
                {
                    field: 'assetsAdmin',
                    align: 'center',
                    title: '管理员',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsAdmin' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsStorage',
                    align: 'center',
                    title: '存放点',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsStorage' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsImg',
                    align: 'center',
                    title: '资产照片',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsImg' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsDesc',
                    align: 'center',
                    title: '备注',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].assetsDesc' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'assetsStatus',
                    align: 'center',
                    title: '设备状态',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("assetsInfoList[%s].assetsStatus", index);
                        return $.common.dictToSelect(assetsStatusDatas, value, name);
                    }
                },
                {
                    field: 'delete',
                    align: 'center',
                    title: '0：正常 1：删除',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].delete' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '入库时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='assetsInfoList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                assetsName: "",
                assetsType: "",
                assetsModel: "",
                assetsSn: "",
                assetsUnit: "",
                assetsSource: "",
                assetsBuytime: "",
                assetsPrice: "",
                assetsArea: "",
                assetsCompany: "",
                assetsAdmin: "",
                assetsStorage: "",
                assetsImg: "",
                assetsDesc: "",
                assetsStatus: "",
                delete: "",
                createTime: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>